<?php
namespace app\admin\model;
use think\Model;
use think\Db;
use app\admin\model\Cuser;

class Withdrawals extends Model
{

    //时间格式化
    public function getCreateTimeTrunAttr($value,$data)
    {
        return date('Y-m-d H:i:s', $data['create_time']);
    }

    //金额数字小数点后2位 设置
    public function getMoneyAttr($value,$data)
    {
        return $get_data = number_format($data['money'],2);
    }

    //设置提现订单状态

    //设置提现类型
    public function getTypeAttr($value, $data)
    {
        $get_data = [
            '0'=>'商家提现',
            '1'=>'用户提现'
        ];

        return $get_data[$data['type']];
    }
    //设置提现的状态
    public function getCodeAttr($value, $data)
    {
        $get_data = [
            '1'=>'微信提现',
            '0'=>'银行卡提现'
        ];

        return $get_data[$data['code']];
    }

    public function getStatusAttr($value,$data)
    {
        $get_data = [
            '0'=>'提现审核中',
            '1'=>'提现完成',
            '2'=>'提现处理中',
            '4'=>'提现关闭'
        ];

        return $get_data[$data['status']];
    }

    public function selectList()
    {
        $field = ['w.id,telphone,account,bank,money,w.status,w.create_time,code,user_id'];
        $data = Db::name('Withdrawals')
                ->alias('w')
                ->join('gx_cuser c','c.id = w.user_id')
                ->field($field)
                ->order('w.id desc')
                ->paginate('',false,page_param());

        return $data;
    }

    public function cuser()
    {
        $data = $this->hasMany('cuser','id','id');

    }
}